package com.woniuxy.oa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.oa.entity.PageBeanList;
import com.woniuxy.oa.entity.Schedule;
import com.woniuxy.oa.mapper.ScheduleMapper;
import com.woniuxy.oa.service.ScheduleService;

@Service
public class ScheduleServiceImpl implements ScheduleService {

	@Autowired
	ScheduleMapper scheduleMapper;
	
	/**
	 * 按条件分页查询
	 */
	@Override
	public PageBeanList<Schedule> getScheduleConditionByPage(int pageIndex, int pageSize, Schedule schedule) {
		//获取总条数
		int totalRecored = scheduleMapper.selectScheduleConditionByPageTotalRecored(schedule);
		//获取模糊查询出来的信息
		List<Schedule> schedules = scheduleMapper.selectScheduleConditionByPage((pageIndex-1)*pageSize, pageSize, schedule);
		//获取自己定义的泛型类
		PageBeanList<Schedule> pageBean=new PageBeanList<Schedule>();
		//给pageBean的BeanList赋值
		pageBean.setBeanList(schedules);
		//把当前页面的页码赋值进去
		pageBean.setPageIndex(pageIndex);
		//把每页显示的页码赋值进去
		pageBean.setPageSize(pageSize);
		//把数据库查询出来的总条数赋值进去
		pageBean.setTotalRecored(totalRecored);
		//调用自己定义类里面自己写的方法   做最后调整  
		pageBean.setPageBeginAndPageEnd();
		return pageBean;
	}

	/**
	 * 添加方法  他这个对象里面回传一个当前登录用户的id
	 */
	@Override
	public void addSchedule(Schedule schedule) {
		scheduleMapper.insertSchedule(schedule);
	}

	/**
	 * 根据s_id取值
	 */
	@Override
	public Schedule getScheduleByS_id(Integer s_id) {
		Schedule schedule = scheduleMapper.selectScheduleByS_id(s_id);
		return schedule;
	}

	/**
	 * 修改某位员工工作计划的方法
	 */
	@Override
	public void modifySchedule(Schedule schedule) {
		scheduleMapper.updateSchedule(schedule);
	}

	/**
	 * 删除日程安排   这里使用软删除
	 */
	@Override
	public void modifySchedule(Integer s_id) {
		scheduleMapper.deleteSchedule(s_id);
	}

}
